﻿@using Owin;
@using Microsoft.AspNet.Identity;
@using Microsoft.AspNet.Identity.Owin;
@{
    ViewBag.Title = "Home Page";
}

<div class="jumbotron">
    <h1>ASP.NET</h1>
    <p class="lead">ASP.NET is a free web framework for building great Web sites and Web applications using HTML, CSS and JavaScript.</p>
    <p><a href="http://asp.net" class="btn btn-primary btn-large">Learn more &raquo;</a></p>
</div>

<div class="row">
    @if (Request.IsAuthenticated)
    {
        using (Html.BeginForm("SignOutEverywhere", "Account", FormMethod.Post, new { id = "signOutEverywhereForm" }))
        {
            @Html.AntiForgeryToken();
    <input type="submit" value="Sign Out Everywhere" class="btn btn-default" />
        }
    }

</div>
<div class="row">
    @if (Request.IsAuthenticated)
    {
        var manager = Request.GetOwinContext().GetUserManager<SingleSignOutSample.Models.ApplicationUserManager>();
        var user = manager.FindById(User.Identity.GetUserId());
        using (Html.BeginForm("SignOutClient", "Account", FormMethod.Post, new { id = "signOutClientForm" }))
        {
            @Html.AntiForgeryToken();
            <input type="hidden" id="clientId" name="clientId" />
        }
        <table>
            <tr>
                <th>
                    Client Key
                </th>
                <th></th>
            </tr>
            @foreach (var client in user.Clients)
            {
            <tr>
                <td>
                   @client.ClientKey
                </td>
                <td>
                    <input type="button" value="Sign Out" onclick="SignOutClient(@client.Id);" class="btn btn-default"></td>
            </tr>
            }
        </table>
    }
</div>

@section scripts{
    <script type="text/javascript">
        function SignOutClient(clientId)
        {
            $("#clientId").val(clientId);
            $("#signOutClientForm").submit();
        }
    </script>
}